package leetcode.n2021;

/**
 * https://leetcode.com/problems/battleships-in-a-board/?tab=Description
 * @program: brushing
 * @description:
 * @author: LiuQiang
 * @create: 2018-07-25 10:41
 **/
public class Battleships {
    // TODO: 2018/7/26
    public int countBattleships(char[][] board) {
        int num = 0;
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                char x = board[i][j];
                if (x == 'x') {
                    if ((i == board.length - 1 || board[i+1][j] == '.') && (j == board[0].length - 1 || board[i][j+1] == '.')) {
                        num++;
                    }
                }
            }
        }
        return num;
    }

    /**
     * 左a1 上a2 右a3 下a4
     *
     * @param args
     * @Description:
     * @version:v1.0
     * @author:LiuQiang
     * @date:2017年2月23日 上午9:00:11
     */
    public static void main(String[] args) {
        char c[][] =
                {
                        {'x', '.', '.', 'x'},
                        {'.', '.', '.', 'x'},
                        {'.', '.', '.', 'x'}
                };

        System.out.println(new Battleships().countBattleships(c));
    }
}
